package com.mad.bakergps;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import android.content.Context;


public class Building {
	private int number;
	private String name;
	private ArrayList<Room> rooms=new ArrayList<Room>();;
	
	//Gets and sets
	public ArrayList<Room> getRooms() {
		return rooms;
	}
	
	public Room getRoomAt(int i)
	{
		return rooms.get(i);
	}

	public void addRoom(Room theRoom) {
		rooms.add(theRoom);
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public static String[] convertToStringArray(ArrayList<Building> theBuildings)
	{
		ArrayList<String> buildingStrings= new ArrayList<String>();
		
		for(Building i:theBuildings)
		{
			buildingStrings.add(i.getName());
		}
		
		return (String  []) buildingStrings.toArray (new String  [buildingStrings.size ()]);
	}
	
	public static ArrayList<Building> getAllBuildings(int xmlid, Context c) throws ParserConfigurationException, SAXException, IOException
	{
		ArrayList<Building> rList;
		SAXParserFactory spf= SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		XMLReader xr = sp.getXMLReader();
		XMLHandler theHandler= new XMLHandler();
		xr.setContentHandler(theHandler);
		InputStream is = c.getResources().openRawResource(xmlid);
		xr.parse(new InputSource(is));
		rList=theHandler.Buildings;
		
		return rList;
	}
	
	

}
